package com.atguigu.springbootdemo.user.controller;

import com.atguigu.springbootdemo.user.bean.UserInfo;
import com.atguigu.springbootdemo.user.mapper.UserInfoMapper;
import com.atguigu.springbootdemo.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author tubage
 * @since 2024-03-13
 */
@RestController
@RequestMapping("/user/userInfo")
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;
    @GetMapping("/getuser/{id}")
    public UserInfo getUser(@PathVariable("id") Integer id) {
        return userInfoService.getById(id);
    }

    @PostMapping("/savaOrUpdateUser")
    public String savaOrUpdateUser(@RequestBody UserInfo userInfo) {
        userInfoService.saveOrUpdate(userInfo);
        return "success";
    }

    @GetMapping("/deleteUser/{id}")
    public String deleteUser(@PathVariable("id") Integer id) {
        userInfoService.removeById(id);
        return "success";
    }

}
